package org.example.mybatis3.service;

import org.example.mybatis3.entity.User;
import org.example.mybatis3.mapper.UserXmlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserXmlService {

    @Autowired
    private UserXmlMapper userMapper;

    public List<User> findAll() {
        return userMapper.findAll();
    }

    public User findById(Long id) {
        return userMapper.findById(id);
    }

    public User findByIdWithResultMapConstructor(Long id) {
        return userMapper.findByIdWithResultMapConstructor(id);
    }

    public Map<String, Object> findByIdWithMap(Long id) {
        return userMapper.findByIdWithMap(id);
    }

    public User findByIdWithPojo(Long id) {
        return userMapper.findByIdWithPojo(id);
    }

    public int save(User user) {
        if (user.getId() == null) {
            return userMapper.insert(user);
        } else {
            return userMapper.update(user);
        }
    }

    public int deleteById(Long id) {
        return userMapper.deleteById(id);
    }
}
